package com.xxx.video.main.adapters;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.main.beans.HomeTypeListBean;
import com.xxx.video.main.fragments.HomeChannelListFragment;

import java.util.List;


public class HomePagerAdapter extends FragmentStateAdapter {
    private List<HomeTypeListBean.TypeListBean> typeList;

    public HomePagerAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        Bundle bundle = new Bundle();
        bundle.putString("Id", typeList.get(position).fId);
        return HomeChannelListFragment.newInstance(bundle);
    }

    @Override
    public int getItemCount() {
        if (ListUtils.isEmpty(typeList)) {
            return 0;
        }
        return typeList.size();
    }

    /**
     * set data
     *
     * @param typeList data
     */
    public void setData(List<HomeTypeListBean.TypeListBean> typeList) {
        this.typeList = typeList;
        notifyDataSetChanged();
    }
}
